//
//  LocationIncubationController.m
//  BigToBig
//
//  Created by yi liu on 16/7/27.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "LocationIncubationController.h"
#import "HomeFunctionView.h"
#import "LocationIncubationCell.h"
#import "SearchViewController.h"
#import "IncubationSpaceDetailsViewController.h"

@interface LocationIncubationController ()
<
UITableViewDelegate,
UITableViewDataSource
>

@property (nonatomic , strong)UISearchBar *searchBar;
@property (nonatomic , strong)HomeFunctionView *homeFunctionView;
@property (nonatomic , strong)UITableView *mainTableView;

@end

@implementation LocationIncubationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setBackBar];
    self.view.backgroundColor = [UIColor whiteColor];
//    self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
//    //    [self.navigationController.navigationBar addSubview:self.searchBar];
//    self.navigationItem.titleView = self.searchBar;
//    self.searchBar.placeholder = @"搜索项目";
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"孵化空间";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(searchAction:)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    // 创建功能区(排序 and 筛选)
    self.homeFunctionView = [[HomeFunctionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
    [self.view addSubview:self.homeFunctionView];
    
    // 创建mainTableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, kScreenWidth, kScreenHeight - 64 - 40)];
    [self.view addSubview:self.mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.mainTableView registerClass:[LocationIncubationCell class] forCellReuseIdentifier:NSStringFromClass([LocationIncubationCell class])];
    self.mainTableView.separatorStyle = NO;
    self.mainTableView.bounces = NO;
    
    
}

- (void)searchAction:(UIBarButtonItem *)buttonItem{
    
    SearchViewController *searchVc = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchVc animated:YES];
}

#pragma mark - tableView 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LocationIncubationCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:NSStringFromClass([LocationIncubationCell class]) forIndexPath:indexPath];
    cell.headImageView.image = [UIImage imageNamed:@"tx"];
    cell.titleLabel.text = @"北航天汇科技孵化器公司";
    cell.describeLabel.text = @"免费提供上下行10G网络,饮水机.";
    cell.areaLabel.text = @"200㎡面积";
    cell.rentLabel.text = @"10000元/平米/年";
    cell.positionlabel.text = @"北京";
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    IncubationSpaceDetailsViewController *incubationSpaceDetailVC = [[IncubationSpaceDetailsViewController alloc]init];
    [self.navigationController pushViewController:incubationSpaceDetailVC animated:YES];
}


#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
}

- (void)backController:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
